//// 单例模式
//package main
//
//import (
//	"fmt"
//	"sync"
//	"sync/atomic"
//)
//
//var lock sync.Mutex
//var initialized uint32
//
//type signalClass struct{}
//
//var instance *signalClass
//
//func GetInstance() *signalClass {
//	if atomic.LoadUint32(&initialized) == 1 {
//		return instance
//	}
//
//	lock.Lock()
//	defer lock.Unlock()
//	instance = new(signalClass)
//	atomic.StoreUint32(&initialized, 1)
//
//	return instance
//}
//
//func main() {
//	a := GetInstance()
//	b := GetInstance()
//	fmt.Printf("%p\n", a)
//	fmt.Printf("%p\n", b)
//}

package main

import (
	"fmt"
	"sync"
)

var once sync.Once

type signalClass struct{}

var signalInstance *signalClass

func GetSignalInstance() *signalClass {
	once.Do(func() {
		signalInstance = new(signalClass)
	})
	return signalInstance
}

func main() {
	a := GetSignalInstance()
	b := GetSignalInstance()
	fmt.Printf("%p\n", a)
	fmt.Printf("%p\n", b)
}
